//
//  WFUserAvatarCell.m
//  WisdomFarm
//
//  Created by sky on 2017/12/9.
//  Copyright © 2017年 sky. All rights reserved.
//

#import "WFUserEditCell.h"

@implementation WFUserEditCell

- (instancetype)initWithStyle:(WFUserEditCellStyle)style {
    if (self = [super init]) {
        _style = style;
        _titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        _iconView = [[UIImageView alloc] init];
        [self.contentView addSubview:_iconView];
        _contentLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_contentLabel];
        
        _arrowView = [[UIImageView alloc] init];
        [self.contentView addSubview:_arrowView];
        
        _titleLabel.font = SCFont(14);
        _titleLabel.textColor = [UIColor textTitleColor];

        _contentLabel.font = SCFont(14);
        _contentLabel.textColor = [UIColor textTitleColor];
        _contentLabel.textAlignment = NSTextAlignmentRight;
        
        _arrowView.image = [UIImage imageNamed:@"about_arrow"];
        _arrowView.contentMode = UIViewContentModeScaleAspectFit;
        
        [self reloadConstraints];
    }
    return self;
}

- (void)reloadConstraints {
    [_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.centerY.offset(0);
    }];
    
    self.arrowView.hidden = (self.style != WFUserEditCellStyleTextWithArrow &&
                             self.style != WFUserEditCellStyleImageWithArrow);
    [_arrowView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-13);
        make.centerY.offset(0);
    }];
    
    self.contentLabel.hidden = (self.style != WFUserEditCellStyleText &&
                                self.style != WFUserEditCellStyleTextWithArrow);
    if (self.style == WFUserEditCellStyleText) {
        [_contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(-13);
            make.centerY.offset(0);
        }];
    } else {
        [_contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.arrowView.mas_left).offset(-6);
            make.centerY.offset(0);
        }];
    }
    
    self.iconView.hidden = (self.style != WFUserEditCellStyleImage &&
                                self.style != WFUserEditCellStyleImageWithArrow);
    if (self.style == WFUserEditCellStyleImage) {
        [self.iconView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(-13);
            make.centerY.offset(0);
            make.width.height.mas_equalTo(44);
        }];
    } else {
        [self.iconView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.arrowView.mas_left).offset(-6);
            make.centerY.offset(0);
            make.width.height.mas_equalTo(44);
        }];
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.iconView.layer.cornerRadius = self.iconView.height / 2;
}

@end
